package com.blb.web;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blb.base.BaseServlet;
import com.blb.service.UserService;
import com.blb.utils.LayuiPage;
import com.google.gson.Gson;

/**
 * 用户分页列表
 * @author Administrator
 *
 */
@WebServlet("/userList")
public class UserListServlet extends BaseServlet {
	
	private static final long serialVersionUID = 1L;
	
	private UserService userService = new UserService();

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		super.setPage(req.getParameter("page"));
		super.setLimit(req.getParameter("limit"));
		String username = req.getParameter("username");
		String job = req.getParameter("job");
		try {
			//查询用户分页对象
			LayuiPage layuiPage = userService.page(super.getPage(), super.getLimit(), username, job);
			
			//将分页对象转为String并写回浏览器
			String data = new Gson().toJson(layuiPage);
			resp.getWriter().write(data);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
